package top.chmin.project.cloud.sys.select.info;

import java.util.stream.Stream;
import java.util.List;
import java.util.ArrayList;

import top.chmin.project.cloud.common.*;
import lombok.experimental.Accessors;
import lombok.Setter;
import lombok.Getter;



/**
 * chmin
 * 2024-01-26 14:02:25
 * cloud-code
 */
public class SelectInfoCondition extends Condition {
    private SelectInfoCondition parent = null;

    SelectInfoCondition() {
    }

    private SelectInfoCondition(SelectInfoCondition condition) {
        this.parent = condition;
    }

    public static SelectInfoCondition forDelete() {
        SelectInfoCondition condition = new SelectInfoCondition();
        condition.setSql("DELETE FROM sys_select_info#where##group##order##limit#");
        return condition;
    }

    public static SelectInfoCondition forSelect() {
        SelectInfoCondition condition = new SelectInfoCondition();
        condition.modelClass = SelectInfo.class;
        condition.setSql("SELECT #select# FROM sys_select_info#where##group##order##limit#");
        return condition;
    }

    public SelectInfoCondition distinct() {
        this.distinct = true;
        return this;
    }

    public SelectInfoCondition limit(int limit) {
        this.limit = " LIMIT " + limit;
        return this;
    }

    public SelectInfoCondition sub() {
        return new SelectInfoCondition(this);
    }

    public SelectInfoCondition finish() {
        if (!whereList.isEmpty()) {
            parent.whereList.add("(" + String.join(" OR ", whereList) + ")");
        }
        parent.whereValueList.addAll(whereValueList);
        return parent;
    }

    public SelectInfo selectFirst() {
        return selectFirst(SelectInfo.class);
    }

    public List<SelectInfo> selectList() {
        return selectList(SelectInfo.class);
    }

    public Stream<SelectInfo> selectStream() {
        return selectStream(SelectInfo.class);
    }

    public Page<SelectInfo> selectPage() {
        return selectPage(SelectInfo.class);
    }

    /*###########auto#start###########*/
    public static int deleteByLabelColumnCodeAndValueColumnCode(String labelColumnCode, String valueColumnCode) {
        return forDelete().labelColumnCode().eq(labelColumnCode).valueColumnCode().eq(valueColumnCode).execute();
    }

    public static SelectInfo selectByLabelColumnCodeAndValueColumnCode(String labelColumnCode, String valueColumnCode) {
        return forSelect().labelColumnCode().eq(labelColumnCode).valueColumnCode().eq(valueColumnCode).selectFirst(SelectInfo.class);
    }

    public static <T> T selectByLabelColumnCodeAndValueColumnCode(String labelColumnCode, String valueColumnCode, Class<T> clazz) {
        return forSelect().labelColumnCode().eq(labelColumnCode).valueColumnCode().eq(valueColumnCode).selectFirst(clazz);
    }

    /*###########auto##end############*/
    /* append $conditionIndexAppender$ */
    /*###########auto#start###########*/
    public CreateBy createBy() {
        return new CreateBy();
    }

    public class CreateBy extends StringFlexColumn<SelectInfoCondition> {
        private CreateBy() {
            super(SelectInfoCondition.this, "create_by");
        }
    }

    public CreateTime createTime() {
        return new CreateTime();
    }

    public class CreateTime extends LocalDateTimeFlexColumn<SelectInfoCondition> {
        private CreateTime() {
            super(SelectInfoCondition.this, "create_time");
        }
    }

    public Id id() {
        return new Id();
    }

    public class Id extends IntegerFlexColumn<SelectInfoCondition> {
        private Id() {
            super(SelectInfoCondition.this, "id");
        }
    }

    public LabelColumnCode labelColumnCode() {
        return new LabelColumnCode();
    }

    public class LabelColumnCode extends StringFlexColumn<SelectInfoCondition> {
        private LabelColumnCode() {
            super(SelectInfoCondition.this, "label_column_code");
        }
    }

    public TableCode tableCode() {
        return new TableCode();
    }

    public class TableCode extends StringFlexColumn<SelectInfoCondition> {
        private TableCode() {
            super(SelectInfoCondition.this, "table_code");
        }
    }

    public UpdateBy updateBy() {
        return new UpdateBy();
    }

    public class UpdateBy extends StringFlexColumn<SelectInfoCondition> {
        private UpdateBy() {
            super(SelectInfoCondition.this, "update_by");
        }
    }

    public UpdateTime updateTime() {
        return new UpdateTime();
    }

    public class UpdateTime extends LocalDateTimeFlexColumn<SelectInfoCondition> {
        private UpdateTime() {
            super(SelectInfoCondition.this, "update_time");
        }
    }

    public ValueColumnCode valueColumnCode() {
        return new ValueColumnCode();
    }

    public class ValueColumnCode extends StringFlexColumn<SelectInfoCondition> {
        private ValueColumnCode() {
            super(SelectInfoCondition.this, "value_column_code");
        }
    }

    /*###########auto##end############*/
    /* append $conditionFieldAppender$ */
}
